package abd.pr1.Interface;

import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;

import abd.pr1.Models.Serie;

public class AdminSeriesPanel extends JPanel {
private static final long serialVersionUID = 1L;
	
	private JList<Serie> listaSeries;
	private JButton info;
	private JButton nueva;
	private JButton buscarButton;
	private JTextField buscarTexto;
	public AdminSeriesPanel(){
		super();
		this.build();
		
	}

	private void build() {
		
		this.setLayout(new BorderLayout());
		
		JPanel buscarContainer = new JPanel(new BorderLayout());
		JLabel buscarSeries = new JLabel("Buscar Serie");
		buscarTexto = new JTextField();
	    buscarButton= new JButton("Buscar");
		buscarButton.setActionCommand("buscar_admin_serie");
		buscarContainer.add(buscarSeries,BorderLayout.WEST);
		buscarContainer.add(buscarTexto,BorderLayout.CENTER);
		buscarContainer.add(buscarButton,BorderLayout.EAST);
		
		this.add(buscarContainer,BorderLayout.NORTH);
				
		listaSeries = new JList<Serie>();
		
		this.add(listaSeries, BorderLayout.CENTER);
		
		JPanel botonesContainer = new JPanel();
	    info= new JButton("Ver informacion");
	    info.setActionCommand("info_admin_serie");
	    
	    nueva= new JButton("Nueva serie");
	    nueva.setActionCommand("nueva_serie");
	    
	    botonesContainer.add(info);
	    botonesContainer.add(nueva);
	    
		this.add(botonesContainer, BorderLayout.SOUTH);

	}
	public String getBuscarTexto(){
		return this.buscarTexto.getText();
	}
	public void addListener(ActionListener a){
		info.addActionListener(a);
		nueva.addActionListener(a);
		buscarButton.addActionListener(a);
	}
	public void setListaseries(List<Serie> series){

		listaSeries.setListData(series.toArray(new Serie[series.size()]));
	}
	public Serie getSelectedSerie(){
		return listaSeries.getSelectedValue();
	}

}
